
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * cliente.java
 *
 * Created on 22/03/2013, 11:39:52 AM
 */

/**
 *
 * @author Usuario Final
 */
public class cliente extends javax.swing.JFrame {
imagencliente icl=new imagencliente ();
  BD bd = new BD();
    /** Creates new form cliente */
    public cliente() {
        initComponents();bd.configurar();add(icl,BorderLayout.CENTER);setLocation(150,70);;setTitle("Software Control de Clientes");
  setResizable(false);
  Mostrar();
    }

public void Mostrar() {

        DefaultTableModel model = new DefaultTableModel();
     model.addColumn("Nombre");
     model.addColumn("Apellido Paterno");
     model.addColumn("Caso");
       model.addColumn("Observaciones");
jTable1.setModel(model);
TableColumn nombre  = jTable1.getColumn("Nombre");
TableColumn apellido = jTable1.getColumn("Apellido Paterno");
TableColumn caso = jTable1.getColumn("Caso");
nombre.setMinWidth(150);nombre.setMaxWidth(150);
apellido.setMinWidth(100);apellido.setMaxWidth(100);
caso.setMinWidth(150);caso.setMaxWidth(150);

}


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jTabbedPane1.addTab("tab1", jScrollPane1);

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("id de Registro:");

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/find.png"))); // NOI18N
        jButton1.setText("Buscar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jMenu1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/fileopen.png"))); // NOI18N
        jMenu1.setText("Archivo");

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/back.png"))); // NOI18N
        jMenuItem1.setText("Inicio");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/admin_icon.png"))); // NOI18N
        jMenuItem2.setText("Entrar Como Administrador");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1075, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(189, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
Home h = new Home();h.setVisible(true);
dispose();
// TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
String x = jTextField1.getText();
int column = jTable1.getSelectedColumn();
  List<String> mostrarclientes[] = bd.busquedaregistro(x);
  DefaultTableModel model = new DefaultTableModel();
DefaultTableCellRenderer centrar = new DefaultTableCellRenderer();
centrar.setHorizontalAlignment(SwingConstants.CENTER);
jTable1.getColumnModel().getColumn(1).setCellRenderer(centrar);


model.addColumn("Nombre");
     model.addColumn("Apellido Paterno");
     model.addColumn("Caso");
     model.addColumn("Observaciones");

     jTable1.setModel(model);
TableColumn nombre  = jTable1.getColumn("Nombre");
TableColumn apellido = jTable1.getColumn("Apellido Paterno");
TableColumn caso = jTable1.getColumn("Caso");
nombre.setMinWidth(150);nombre.setMaxWidth(150);
apellido.setMinWidth(100);apellido.setMaxWidth(100);
caso.setMinWidth(100);caso.setMaxWidth(100);
     int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,cont=1;

    for (String numero : mostrarclientes[0]) {
        model.addRow(new Object[]{cont});
        cont=cont+1;
        }

 for (String nom : mostrarclientes[0] ) {
           jTable1.setValueAt(nom, b ,0);
           b=b+1; }

       for (String nom : mostrarclientes[1] ) {
           jTable1.setValueAt(nom, c ,1);
           c=c+1; }

        for (String nom : mostrarclientes[2] ) {
           jTable1.setValueAt(nom, d ,2);
           d=d+1; }
 for (String nom : mostrarclientes[3] ) {
           jTable1.setValueAt(nom, e ,3);
           e=e+1; }

    }//GEN-LAST:event_jButton1ActionPerformed
public Icon getIcon1(){
 return new ImageIcon(getClass().getResource("/Imagenes/mail_find.png"));}
    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed
    int x = jTable1.getSelectedRow();
String observacion = (String) jTable1.getModel().getValueAt(x, 3);

JOptionPane.showMessageDialog(null,"Observaciones: \n"+observacion,"Observaciones",JOptionPane.PLAIN_MESSAGE,getIcon1());




    }//GEN-LAST:event_jTable1KeyPressed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
Contra p = new Contra();p.setVisible(true);dispose();


    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed

if(evt.getSource()==jTextField1){
    String x = jTextField1.getText();
  List<String> mostrarclientes[] = bd.busquedaregistro(x);
  DefaultTableModel model = new DefaultTableModel();
//int column = jTable1.getSelectedColumn();
     model.addColumn("Nombre");
     model.addColumn("Apellido Paterno");
     model.addColumn("Caso");
     model.addColumn("Observaciones");
DefaultTableCellRenderer centrar = new DefaultTableCellRenderer();
centrar.setHorizontalAlignment(SwingConstants.CENTER);
jTable1.getColumnModel().getColumn(1).setCellRenderer(centrar);
     jTable1.setModel(model);

TableColumn nombre  = jTable1.getColumn("Nombre");
TableColumn apellido = jTable1.getColumn("Apellido Paterno");
TableColumn caso = jTable1.getColumn("Caso");
nombre.setMinWidth(150);nombre.setMaxWidth(150);
apellido.setMinWidth(100);apellido.setMaxWidth(100);
caso.setMinWidth(100);caso.setMaxWidth(100);
     int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,cont=1;

    for (String numero : mostrarclientes[0]) {
        model.addRow(new Object[]{cont});
        cont=cont+1;
        }

 for (String nom : mostrarclientes[0] ) {
           jTable1.setValueAt(nom, b ,0);
           b=b+1; }

       for (String nom : mostrarclientes[1] ) {
           jTable1.setValueAt(nom, c ,1);
           c=c+1; }

        for (String nom : mostrarclientes[2] ) {
           jTable1.setValueAt(nom, d ,2);
           d=d+1; }
 for (String nom : mostrarclientes[3] ) {
           jTable1.setValueAt(nom, e ,3);
           e=e+1; }
     }
    }//GEN-LAST:event_jTextField1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new cliente().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}
